package cn.ynrcb.personnelfile.sysadmin.service.impl;


import cn.ynrcb.personnelfile.sysadmin.entity.SysUserEntity;
import cn.ynrcb.personnelfile.sysadmin.service.CurrentUserService;
import cn.ynrcb.personnelfile.sysadmin.service.SysOrgService;
import cn.ynrcb.personnelfile.sysadmin.service.SysUserRoleService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("currentUserService")
public class CurrentUserServiceImpl implements CurrentUserService {
	@Autowired
	private SysOrgService sysOrgService;

	@Autowired
	private SysUserRoleService sysUserRoleService;

	@Override
	public SysUserEntity getUser() {
		return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
	}

	@Override
	public Long getUserId() {
		return getUser().getUserId();
	}

	@Override
	public Integer getUserRoleId() {
		List<Integer> roles = sysUserRoleService.queryRoleIdList(getUser().getUserId());
		return Integer.parseInt(roles.get(0).toString());
	}

	@Override
	public String getInnerCode() {
//		SysOrgEntity org = sysOrgService.getById(getUser().getOrgId());
//		return org.getInnerCode();
		return null;
	}

	@Override
	public Long getCurrentUserId() {
		return getUser().getUserId();
	}
}
